package com.woniuxy.microgoodsserver.sortmag.mapper;

import com.woniuxy.microcommonserver.bean.gy.GoodCategoryInfo1;
import com.woniuxy.microcommonserver.bean.gy.GoodCategoryInfo2;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.DeleteMapping;

import java.util.List;
import java.util.Map;

/**
    调用分类数据库操作
 * @params:
 * @return
 */
@Mapper
public interface GoodCategoryMapper {
    /**
        增添二级目录
     * @params:
     * @return
     */
    @Insert("insert into good_category_info1(parent_name,good_model,visit_path,page_title," +
            "page_keyword,page_desc,order_model,good_template,sort,image,status,upper_name) values(#{g.parentName},#{g.goodModel}," +
            "#{g.visitPath},#{g.pageTitle},#{g.pageKeyword},#{g.pageDesc},#{g.orderModel},#{g.goodTemplate},#{g.sort},#{g.image},0,#{g.upperName})")
    public void addSort1(@Param("g") GoodCategoryInfo1 goodCategoryInfo1);

    /**
        增添子目录
     * @params:
     * @return
     */
    @Insert("insert into good_category_info2(name,visit_path,good_model,sort,image,good_category_info1_id,status,order_model) " +
            "values(#{g.parentName},#{g.visitPath},#{g.goodModel},#{g.sort},#{g.image},#{parentId},0,#{g.orderModel})")
    public void addSort2(@Param("g") GoodCategoryInfo1 goodCategoryInfo1,@Param("parentId") Integer parentId);


    @ResultType(Integer.class)
    @Select("select id from good_category_info1 where parent_name=#{upperName}")
    public Integer findIdByParentName(String upperName);
    /**
        查询good_category_info1表是否存在
     * @params:
     * @return
     */
    @ResultType(GoodCategoryInfo1.class)
    @Select("select id from good_category_info1 where parent_name = #{g.parentName}")
    public GoodCategoryInfo1 findParentList(@Param("g") GoodCategoryInfo1 goodCategoryInfo1);

    /**
        查询子类目录是否存在
     * @params:
     * @return
     */
    @ResultType(GoodCategoryInfo1.class)
    @Select("select id from good_category_info2 where name=#{g.parentName}")
    public GoodCategoryInfo1 findSonList(@Param("g")GoodCategoryInfo1 goodCategoryInfo1);


    /**查询所有的一级目录

     * @params:
     * @return
     */
    @ResultType(GoodCategoryInfo1.class)
    @Select("select id,parent_name parentName,visit_path visitPath,sort,upper_name upperName from good_category_info1 where status=0")
    public List<GoodCategoryInfo1> findAllParent();


    /**
        根据ID查询所有的二级子目
     * @params:
     * @return
     */
    @ResultType(GoodCategoryInfo2.class)
    @Select("select id,name,visit_path visitPath,sort from good_category_info2 where good_category_info1_id=#{g.id} and status=0")
    public List<GoodCategoryInfo2> findSortById(@Param("g") GoodCategoryInfo1 goodCategoryInfo1);

    /**
        删除一级目录的分类
     * @params:
     * @return
     */
    @Update("update good_category_info1 set status=1 where id=#{g.id}")
    public void deleteSortById1(@Param("g") GoodCategoryInfo1 goodCategoryInfo1);
    /**
        删除二级子目的分类
     * @params:
     * @return
     */
    @Update("update good_category_info2 set status=1 where id=#{g.id}")
    public void deleteSortById2(@Param("g") GoodCategoryInfo1 goodCategoryInfo1);

    /**
        根据ID查找一级分类，并显示出来修改使用
     * @params:
     * @return
     */
    @ResultType(Map.class)
    @Select("select id,parent_name parentName,good_model goodModel,visit_path visitPath,page_title pageTitle," +
            "page_keyword pageKeyword,page_desc pageDesc,order_model orderModel," +
            "good_template goodTemplate,sort sort,image image,upper_name upperName from good_category_info1 where id=#{g.id} and status=0")
    public List<Map> getSort1(@Param("g")GoodCategoryInfo1 goodCategoryInfo1);


    /**
        根据id查找子目（）分类，并显示出来修改使用
     * @params:
     * @return
     */
    @ResultType(Map.class)
    @Select("select g2.id,g2.name,g2.good_model,g2.visit_path," +
            "g2.order_model," +
            "g2.sort,g2.image,g1.parent_name " +
            "from good_category_info2 g2,good_category_info1 g1 where g2.id=#{g.id} and " +
            "g2.good_category_info1_id=g1.id and g2.status=0")
    public List<Map> getSort2(@Param("g")GoodCategoryInfo1 goodCategoryInfo1);



    /**
        修改一级目录
     * @params:
     * @return
     */
    public void updateSort1(@Param("g") GoodCategoryInfo1 goodCategoryInfo1);
    /**
        修改子目录
     * @params:
     * @return
     */
    public void updateSort2(@Param("g")GoodCategoryInfo1 goodCategoryInfo1);

    /**
        根据子目名称查询ID
     * @params:
     * @return
     */
    @ResultType(GoodCategoryInfo2.class)
    @Select("select id from good_category_info2 where name = #{name}")
    public GoodCategoryInfo2 findSonIdByName(@Param("name") String name);
}
